<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/14
 * Time: 11:03
 */

include_once '../tools/DbTools.php';

$oldmoney = $_POST['oldmoney'];
$addmoney = $_POST['addmoney'];
$incardno = $_POST['incardno'];
$newmoney = $oldmoney-$addmoney;

session_start();
$usreInfo = $_SESSION[$_COOKIE['Token']];
$CardId = $usreInfo['CardId'];

DbTools::InitDb();
$date = DbTools::select("SELECT CardId,CardMoney from bankcard where CardNo = '$incardno'");
$CardId1 = $date[0]['CardId'];
$CardMoney1 = $date[0]['CardMoney'];
$newmoney1 = $CardMoney1+$addmoney;

if($newmoney>0){
    $resutl = DbTools::noSelect("INSERT INTO cardtransfer(CardIdOut,CardIdIn,TransferMoney,TransferTime) VALUES($CardId,$CardId1,$addmoney,NOW())");
    $resutl1 = DbTools::noSelect("UPDATE bankcard set CardMoney = $newmoney  WHERE CardId = $CardId");
    $resutl2 = DbTools::noSelect("UPDATE bankcard set CardMoney = $newmoney1  WHERE CardId = $CardId1");
    if($resutl['status'] && $resutl1['status'] && $resutl2['status']){
        echo '转账成功';
        echo '<br />';
        echo '<a href="../user/userInfo.php">返回</a>';
    }else{
        echo '转账失败： '.$resutl['message'].$resutl1['status'].$resutl2['status'];
    }
}else{
    echo '账号余额不足';
    echo '<br />';
    echo '<a href="../user/userInfo.php">返回</a>';
}






